//
//  MeAddressCell.m
//  Ginix
//
//  Created by 冯志强 on 2025/2/24.
//

#import "MeAddressCell.h"
#import "MeAddressNewVC.h"
@interface MeAddressCell()
@property (nonatomic,strong) UIView * line;
@property (nonatomic,strong) YYLabel * nameLabel;
@property (nonatomic,strong) YYLabel * addressLabel;
@property (nonatomic,strong) UIButton * editBtn;
@property (nonatomic,strong) UILabel * morenLabel;

@property (nonatomic,strong) AddressListModel * model;

@end

@implementation MeAddressCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setSubViewLayout];
    }
    return self;
}
-(void)setSubViewLayout{
    
    [self addSubview:self.line];
    [_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(345 * FMScaleX, 2 ));
        make.centerX.bottom.equalTo(@0);
    }];
   
    [self addSubview:self.nameLabel];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(16 * FMScaleX);
        make.top.mas_offset(16 * FMScaleX);
    }];
    [self addSubview:self.morenLabel];
    [_morenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(10 * FMScaleX);
        make.centerY.equalTo(self.nameLabel);
        make.size.mas_offset(CGSizeMake(50 * FMScaleX, 26 * FMScaleX));
    }];
    [self addSubview:self.addressLabel];
    [_addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(300 * FMScaleX, 50 * FMScaleX));
        make.left.equalTo(self.nameLabel);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(10 * FMScaleX);
    }];
    [self.contentView addSubview:self.editBtn];
    [_editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(30 * FMScaleX, 30 * FMScaleX));
        make.right.mas_offset(-23 * FMScaleX);
        make.top.mas_offset(50 * FMScaleX);
    }];
}

-(void)setInfoModel:(AddressListModel *)infoModel{
    
    self.model = infoModel;
    self.nameLabel.text = [NSString stringWithFormat:@"%@ %@",infoModel.name,infoModel.phone];
    self.addressLabel.text = [NSString stringWithFormat:@"%@%@%@%@",infoModel.province,infoModel.city,infoModel.district,infoModel.detailAddress];
    if (infoModel.type == 0) {
        self.morenLabel.hidden = YES;
    }else{
        self.morenLabel.hidden = NO;
    }
}

-(void)editBtnAction{
    
    MeAddressNewVC * vc = [[MeAddressNewVC alloc]initWithType:1 model:self.model];
    [[UIViewController findNavigationController] pushViewController:vc animated:YES];
}

-(UIView *)line{
    
    if (!_line) {
        _line = [[UIView alloc]init];
        _line.backgroundColor = RDRGB(0xF8F7F4);
    }
    return _line;
}

-(YYLabel *)nameLabel{
    
    if(!_nameLabel){
        _nameLabel = [[YYLabel alloc]init];
        _nameLabel.font = Semibold(17);
        _nameLabel.textColor = RDRGB(0x333333);
    }
    return _nameLabel;
}
-(YYLabel *)addressLabel{
    
    if(!_addressLabel){
        _addressLabel = [[YYLabel alloc]init];
        _addressLabel.font = Regular(16);
        _addressLabel.textColor = RDRGB(0x666666);
        _addressLabel.numberOfLines = 0;
    }
    return _addressLabel;
}
-(UILabel *)morenLabel{
    
    if (!_morenLabel) {
        _morenLabel = [[UILabel alloc]init];
        _morenLabel.backgroundColor = RDRGB(0xE8DFD4);
        _morenLabel.textColor = RDRGB(0x714933);
        _morenLabel.font = Medium(14);
        _morenLabel.text = @"默认";
        _morenLabel.textAlignment = NSTextAlignmentCenter;
        [_morenLabel setCornerRadius:4 * FMScaleX];
    }
    return _morenLabel;
}
-(UIButton *)editBtn{
    
    if (!_editBtn) {
        _editBtn = [[UIButton alloc]init];
        [_editBtn setImage:[UIImage imageNamed:@"Me_address_edit"] forState:UIControlStateNormal];
        [_editBtn addTarget:self action:@selector(editBtnAction ) forControlEvents:UIControlEventTouchUpInside];
    }
    return _editBtn;
}
@end
